package com.woniu.elderly.serve.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.common.dto.ServeWorkOrderDTO;
import com.woniu.common.entity.DealOrder;
import com.woniu.common.entity.Result;
import com.woniu.common.entity.ServeWorkOrder;
import com.woniu.elderly.serve.service.ServeWorkOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/serveworkorder")
public class ServeWorkOrderController {
    @Autowired
    private ServeWorkOrderService serveWorkOrderService;

    //查询所有工单
    @PostMapping("/{pageIndex}/{pageSize}")
    public Result<Page<ServeWorkOrder>> findAll(@PathVariable("pageIndex") int pageIndex,
                                @PathVariable("pageSize") int pageSize,
                                @RequestBody ServeWorkOrderDTO serveWorkOrderDTO){
        log.info("serveworkorder-findAll:pageIndex={},pageSize={},serveWorkOrderDTO={}", pageIndex, pageSize, serveWorkOrderDTO);
        return Result.ok(serveWorkOrderService.findAll(pageIndex, pageSize, serveWorkOrderDTO));
    }
    //根据id查询工单
    @GetMapping("/{id}")
    public Result<ServeWorkOrder> findById(@PathVariable("id") int id){
        log.info("serveworkorder-findById:id={}", id);
        return Result.ok(serveWorkOrderService.findById(id));
    }

    //添加工单
    @PostMapping("/")
    public Result<Void> add(@RequestBody DealOrder dealOrder){
        /*DealOrder dealOrder = new DealOrder();
        dealOrder.setOrderId(1);
        dealOrder.setCategory_id(1);*/
        log.info("serveworkorder-add:dealOrder={}", dealOrder);
        serveWorkOrderService.add(dealOrder);
        return Result.ok();
    }

    //删除工单
    @DeleteMapping("/{id}")
    public Result<Void> remove(@PathVariable("id") int id){
        log.info("serveworkorder-remove:id={}", id);
        serveWorkOrderService.remove(id);
        return Result.ok();
    }

    //修改工单
    @PutMapping("/")
    public Result<Void> modify(@RequestBody ServeWorkOrder serveWorkOrder){
        log.info("serveworkorder-modify:serveWorkOrder={}", serveWorkOrder);
        serveWorkOrderService.modify(serveWorkOrder);
        return Result.ok();
    }
}
